﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            IsLogin();
        }
    }   

    protected void IsLogin()
    {
        login.Visible = true;
        logout.Visible = false;
        DropMenu.Visible = false;
        ManageMenu.Visible = false;
        if (Session["userinfo"] != null)
        {
            login.Visible = false;
            logout.Visible = true;
            DropMenu.Visible = true;
            userInfo.Text = "您好! " + Session["EmpName"] + " 工号:" + Session["EmpID"] + " 部门:" + Session["GroupName"];
            if (Session["IsAdmin"] != null && Session["IsAdmin"].ToString() == "True")
            {
                ManageMenu.Visible = true;
                //这边获取一下是否存在用户申请工作认证，如果有就弹出提示
                string cmd = string.Format(@"Select Count(*) as Num from (Select distinct ViewLog.[No] from UserList INNER JOIN
                                            ViewLog ON UserList.[EmpID] = ViewLog.[EmpID] where (UserList.GroupName = '{0}' and ViewLog.NeedConfirm = true and ViewLog.CThisJob = false))", Session["GroupName"].ToString());
                DBOperate myDB = new DBOperate();
                myDB.SetCommandString(cmd);
                OleDbDataReader dbReader = myDB.ExecuteReader();
                if(dbReader.HasRows)
                {
                    dbReader.Read();
                    userInfo.Text += "&nbsp;&nbsp;&nbsp;<img src=\"Images/msg.png\" /><a href=\"VerifyJob.aspx\">您有" + dbReader["Num"].ToString() + "条工作认证申请待确认。</a>";
                }
                myDB.CloseDB();
            }
        
        }
    }

}
